home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Best of www.BestZips.com (Collector's Edition)
/
Best of WWW.BESTZIPS.COM Collector's Edition (JCSM Shareware) (JCS Marketing).ISO
/
prgtools
/
tn2.zip
/
EUCLID.T
< prev
next >
Wrap
Text File
|
1996-11-15
|
871b
|
56 lines
%
% "euclid.t" finds the greatest common denominator
% of two integers using Euclid's algorithm
%
% Sample program for the T Interpreter by:
%
% Stephen R. Schmitt
% 962 Depot Road
% Boxborough, MA 01719
%
var x, y, z : int
program
put "Numbers must be positive integers!"
prompt "enter numerator:"
get x
assert x > 0
prompt "enter denominator:"
get y
assert y > 0
z := gcd( x, y )
put "greatest common denominator = ", z
put "smallest numerator = ", x/z
put "smallest denominator = ", y/z
end program
function gcd( u : int, v : int ) : int
var t : int
loop
exit when u <= 0
if u < v then
t := u
u := v
v := t
end if
u := u - v
end loop
return v
end function